#include <stdlib.h>
#include <stdio.h>
#include <nds.h>
#include <xlibrary.h>

// global headers
#include "common.h"

// local headers
#include "layout.h"
#include "video_window.h"

#include "window.h"

sLayout *w_addLayout(sWindow *win, u32 flags, sZone *zone) {
	if(win->layout) {
		return l_append(win->layout, flags, zone);
	}
	else {
		win->layout=l_new(flags, zone);
		return win->layout;
	}
}

sWGeometry w_getGeometry(sWindow *win) {
	if(!win) return (sWGeometry){0, 0};

	sWGeometry wgeo;
	sLGeometry lgeo;
//	sThGeometry thgeo;	TODO

	lgeo=l_getGeometry(win->layout);
//	thgeo=th_getWinDecoGeometry(theme);	// get decoration geometry

	wgeo.lwidth=lgeo.width;
	wgeo.lheight=lgeo.height;

	wgeo.width=lgeo.width/*+thgeo.width*/;
	wgeo.height=lgeo.height/*+thgeo.height*/;

	return wgeo;
}

int w_init(sWindow *win) {
	if(!win) return 1;

	win->geo=w_getGeometry(win);

	return 0;
}

int w_render(sWindow *win) {
	if(!win) return 1;

	video_setStartPosition(win->x, win->y);
	video_gotoStartPosition();

	return l_render(win->layout, win->geo.lwidth, win->geo.lheight);
}

